package models;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;

import play.data.validation.Required;
import play.db.jpa.Model;

/**
 * 权限系统模块>>Actions关联User所有Action（活动，操作，模块等等行为）的权限
 * 
 * @see BaseModule
 * @since 1.0
 * @author Mr.J.
 * **/
@Entity
public class Actions extends Model implements BaseModule{
	@Required
	public String name;
	
	@Required
	public String url;
	
	/** 权重值，默认为0 **/
	public int weight = 0;
	
	/** parent用于关联子权限，如“管理模块”内的CRUD操作的权限分配，如果没有则为NULL **/
	@OneToOne
	public Actions parent;
	
	@ManyToMany(mappedBy="actions",cascade=CascadeType.DETACH)
	public List<User> users;

	public Actions(String name, Actions parent, int weight) {
		super();
		this.name = name;
		this.parent = parent;
		this.weight = weight;
	}
	
	public Actions(String name, Actions parent, int weight, String url) {
		super();
		this.url = url;
		this.name = name;
		this.parent = parent;
		this.weight = weight;
	}
}
